﻿namespace TUnit.Assertions.Tests.Helpers;

public class StringDifferenceTests
{
    [Test]
    public async Task Works_For_Empty_String_As_Actual()
    {
        var expectedMessage = """
                              Expected to be equal to "some text"
                              but found ""

                              at Assert.That(actual).IsEqualTo(expected)
                              """.NormalizeLineEndings();
        var actual = "";
        var expected = "some text";

        var sut = async ()
            => await Assert.That(actual).IsEqualTo(expected);

        var exception = await Assert.That(sut).ThrowsException();
        await Assert.That(exception.Message.NormalizeLineEndings()).IsEqualTo(expectedMessage);
    }

    [Test]
    public async Task Works_For_Empty_String_As_Expected()
    {
        var expectedMessage = """
                              Expected to be equal to ""
                              but found "actual text"

                              at Assert.That(actual).IsEqualTo(expected)
                              """.NormalizeLineEndings();
        var actual = "actual text";
        var expected = "";

        var sut = async ()
            => await Assert.That(actual).IsEqualTo(expected);

        var exception = await Assert.That(sut).ThrowsException();
        await Assert.That(exception.Message.NormalizeLineEndings()).IsEqualTo(expectedMessage);
    }

    [Test]
    public async Task Works_When_Actual_Starts_With_Expected()
    {
        var expectedMessage = """
                              Expected to be equal to "some text"
                              but found "some"

                              at Assert.That(actual).IsEqualTo(expected)
                              """.NormalizeLineEndings();
        var actual = "some";
        var expected = "some text";

        var sut = async ()
            => await Assert.That(actual).IsEqualTo(expected);

        var exception = await Assert.That(sut).ThrowsException();
        await Assert.That(exception.Message.NormalizeLineEndings()).IsEqualTo(expectedMessage);
    }

    [Test]
    public async Task Works_When_Expected_Starts_With_Actual()
    {
        var expectedMessage = """
                              Expected to be equal to "some"
                              but found "some text"

                              at Assert.That(actual).IsEqualTo(expected)
                              """.NormalizeLineEndings();
        var actual = "some text";
        var expected = "some";

        var sut = async ()
            => await Assert.That(actual).IsEqualTo(expected);

        var exception = await Assert.That(sut).ThrowsException();
        await Assert.That(exception.Message.NormalizeLineEndings()).IsEqualTo(expectedMessage);
    }
}
